package com.katsu.myapplib.util;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

public final class UtilKeyBoard {

    private UtilKeyBoard() {}

    @TargetApi(Build.VERSION_CODES.CUPCAKE)
    public static void openKeybord(EditText editText) {

        try {

            editText.findFocus();

        } catch (Exception e) {}

        InputMethodManager inputMethodManager = (InputMethodManager) AppApplication.INSTANCE.getSystemService(Context.INPUT_METHOD_SERVICE);

        inputMethodManager.showSoftInput(editText, InputMethodManager.RESULT_SHOWN);

        inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

    }

    @TargetApi(Build.VERSION_CODES.CUPCAKE)
    public static void closeKeybord(EditText editText) {

        try {

            editText.clearFocus();

        } catch (Exception e) {}

        InputMethodManager inputMethodManager = (InputMethodManager) AppApplication.INSTANCE.getSystemService(Context.INPUT_METHOD_SERVICE);

        inputMethodManager.hideSoftInputFromWindow(editText.getWindowToken(), 0);

    }
}
